<template>
    <div class="home-recommend">
        <h2>热门歌手</h2>
        <div class="wrapper" ref="wrapper">
            <ul class="content" ref="content">
                <li v-for="(item, index) in singerList" :key="index" @click="selectItem(item)">
                    <div class="cover">
                        <van-image :src="item.singer_pic" radius="1rem" />
                    </div>
                    <span>{{ item.singer_name }}</span>
                </li>
            </ul>
        </div>
    </div>
</template>
  
<script>
import { betterScrollHorizontal } from "@/common/betterScroll";

export default {
    name: "HomeSinger",
    data() {
        return {
            singerList: []
        }
    },
    created() {
        this.getSingerListData()
    },
    methods: {
        getSingerListData() {
            this.$request('get', '/singer/list')
                .then((res) => {

                    if (res.result == 100) {
                        this.singerList = res.data.list.slice(0, 10)
                    }
                    betterScrollHorizontal(
                        this,
                        this.$refs.wrapper,
                        this.$refs.content,
                        this.singerList.length,
                        10) //调用横向滚动的方法
                })
        },
        selectItem(item) {
            const id = item.singer_mid;
            // this.$store.commit("saveSinger", item)
            this.$store.dispatch("saveSinger", item)
            this.$router.push({
                name: "SingerHome",
                params: { id }
            })

        }

    }
}

</script>
  
<style scoped>
h2 {
    margin-left: 0.2rem;
}

.wrapper {
    width: 100%;
    overflow: hidden;
}


ul.content li {
    display: inline-block;
    width: 10rem;
    vertical-align: top;
}

ul.content li * {
    margin: 0.1rem;
}

ul.content li>span {
    display: inline-block;
    width: 100%;
    font-size: 0.8rem;
    color: #54493B;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
</style>